<script setup>
import InputEditer from '../components/InputEditer.vue'
import InputEditerArrText from '../components/InputEditerArrText.vue'
import InputEditerArrPer from '../components/InputEditerArrPer.vue'
import InputEditerArrPer1 from '../components/InputEditerArrPer1.vue'
import InputEditerArrPer2 from '../components/InputEditerArrPer2.vue'
import InputEditerArrPer3 from '../components/InputEditerArrPer3.vue'
import InputEditerArrPerEdit from '../components/InputEditerArrPerEdit.vue'
import { ref, onMounted, nextTick } from 'vue'
import { dataProcessing_pre_1 } from '../js/dataPro_pre_1.js'
import { dataProcessing_pre_2 } from '../js/dataPro_pre_2.js'
import { dataProcessing_pre_3 } from '../js/dataPro_pre_3.js'
import { dataProcessing_pre_4 } from '../js/dataPro_pre_4.js'

import { _getData } from '/src/api/parameterConfiguration/getData.js'
import { mainStore } from '/src/store/mainStore.js'

const store = mainStore()

let data = ref(null)

const handleTitleClick = async (value) => {
  // 清空当前的所有东西
  store.saveAllData = []
  store.perTitle = value
  switch (value) {
    case 1:
      store.cutArgPage = 'perception-obstacles-polefusion-soft'
      break
    case 2:
      store.cutArgPage = 'perception-obstacles-soft'
      break
    case 3:
      store.cutArgPage = 'perception-obstacles-polefusion-alg'
      break
    case 4:
      store.cutArgPage = 'perception-obstacles-alg'
      break
  }
  getList(value)
}
const getList = async (value) => {
  const res = await _getData(store.cutArgPage)
  if (res?.data?.code != 200) return ElMessage.error('获取数据失败')
  console.log(res)

  switch (value) {
    case 1:
      data.value = dataProcessing_pre_1(res.data.data)
      break
    case 2:
      data.value = dataProcessing_pre_2(res.data.data)
      console.log(data.value)
      break
    case 3:
      data.value = dataProcessing_pre_3(res.data.data)
      break
    case 4:
      data.value = dataProcessing_pre_4(res.data.data)
      break
  }
}

getList(store.perTitle)

let height = ref('0px')
onMounted(() => {
  nextTick(() => {
    const h = document.querySelector('.pre-container').getBoundingClientRect().height
    height.value = h - 42 + 'px'
  })
})
</script>

<template>
  <div class="pre-container">
    <!-- 主要的参数 -->
    <div class="title">
      <div @click="handleTitleClick(1)" :class="store.perTitle == 1 ? 'selecdCss' : ''">单杆融合-软件</div>
      <div @click="handleTitleClick(2)" :class="store.perTitle == 2 ? 'selecdCss' : ''">多杆融合-软件</div>
      <div @click="handleTitleClick(3)" :class="store.perTitle == 3 ? 'selecdCss' : ''">单杆融合-算法</div>
      <div @click="handleTitleClick(4)" :class="store.perTitle == 4 ? 'selecdCss' : ''">多杆融合-算法</div>
    </div>

    <div class="show-main" :style="{ height: height }" v-if="data?.data_main1 && store.perTitle == 1">
      <div class="show-item" v-for="iten in data.data_main1">
        <p class="showTitle">{{ iten.title }}</p>
        <div class="input-main" v-for="item in iten.data">
          <InputEditer v-if="!item.arr" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrText v-if="item.arr && item.showType == 'text'" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrPer1 v-if="item.arr && item.showType == 'numArrSymbol'" :data="item" :width="320" />
          <InputEditerArrPer3 v-if="item.arr && item.showType == 'object'" :data="item" :width="320" />
        </div>
      </div>
    </div>

    <div class="show-main" :style="{ height: height }" v-if="data?.data_main2 && store.perTitle == 2">
      <div class="show-item" v-for="iten in data.data_main2">
        <p class="showTitle">{{ iten.title }}</p>
        <div class="input-main" v-for="item in iten.data">
          <InputEditer v-if="!item.arr" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrText v-if="item.arr && item.showType == 'text'" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrPer1 v-if="item.arr && item.showType == 'numArrSymbol'" :data="item" :width="320" />
          <InputEditerArrPer3 v-if="item.arr && item.showType == 'object'" :data="item" :width="320" />
        </div>
      </div>
    </div>

    <div class="show-main" :style="{ height: height }" v-if="data?.data_main3 && store.perTitle == 3">
      <div class="show-item" v-for="iten in data.data_main3">
        <p class="showTitle">{{ iten.title }}</p>
        <div class="input-main" v-for="item in iten.data">
          <InputEditer v-if="!item.arr" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrText v-if="item.arr && item.showType == 'text'" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrPerEdit v-if="item.arr && item.showType == 'eidtArr'" :data="item" :width="320" :boxWidth="1000" />
          <InputEditerArrPer1 v-if="item.arr && item.showType == 'numArrSymbol'" :data="item" :width="320" />
          <InputEditerArrPer2 v-if="item.arr && item.showType == 'numArr'" :data="item" :width="320" />
          <InputEditerArrPer3 v-if="item.arr && item.showType == 'object'" :data="item" :width="320" />
        </div>
      </div>
    </div>

    <div class="show-main" :style="{ height: height }" v-if="data?.data_main4 && store.perTitle == 4">
      <div class="show-item" v-for="iten in data.data_main4">
        <p class="showTitle">{{ iten.title }}</p>
        <div class="input-main" v-for="item in iten.data">
          <InputEditer v-if="!item.arr" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrText v-if="item.arr && item.showType == 'text'" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrPer v-if="item.arr && item.showType == 'arrText'" :data="item" :width="320" :inputWidth="'360px'" />
          <InputEditerArrPer2 v-if="item.arr && item.showType == 'numArr'" :data="item" :width="320" />
          <InputEditerArrPer3 v-if="item.arr && item.showType == 'object'" :data="item" :width="320" />
          <InputEditerArrPerEdit v-if="item.arr && item.showType == 'eidtArr'" :data="item" :width="320" :boxWidth="400" />
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.pre-container {
  width: 100%;
  height: 100%;
  font-size: 14px;
  padding: 0 6px 0 20px;
  display: flex;
  flex-direction: column;
}

.show-item {
  margin-bottom: 10px;
}

.title {
  width: 100%;
  margin-top: 10px;
  display: flex;
  align-items: center;
  > div {
    width: 120px;
    margin-right: 10px;
    height: 22px;
    background-color: #ccc;
    line-height: 22px;
    border-radius: 2px;
    cursor: pointer;
    text-align: center;
  }
}

.title2 {
  color: blue;
}

.selecdCss {
  color: white;
  background-color: #4095e5 !important;
}

.showTitle {
  color: purple;
}

.show-main {
  width: 100%;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  overflow-y: auto;
  margin-top: 10px;

  .input-main {
    width: 100%;
    min-height: 40px;
    min-width: 500px;
    margin-top: 10px;
    padding: 0 20px;
    overflow-y: auto;
  }
  .title {
    color: blue;
    margin-bottom: 10px;
    padding-left: 40px;
  }
}

.show-main2 {
  margin-top: 20px;
}

.item {
  display: flex;
  align-items: center;
}
</style>
